#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import requests, json, sys
import traceback

s = requests.Session()


def login(username, password):
    """
    模拟登录新浪微博
    :param username: 用户名
    :param password: 密码
    :return:
    """
    global res
    login_url = 'https://passport.weibo.cn/sso/login'
    headers = {
        'Referer': 'https://passport.weibo.cn/signin/login?entry=mweibo&res=wel&wm=3349&r=https%3A%2F%2Fm.weibo.cn%2F',
        'User-Agent': 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Mobile Safari/537.36'}
    data = {
        'username': username,
        'password': password
    }
    try:
        res = s.post(login_url, data, headers=headers)
        res.raise_for_status()
    except Exception as e:
        traceback.print_exc()
        print("登录失败")
        return 0
    # print(res.text)
    if json.loads(res.text)['retcode'] == 20000000:
        return 1
    else:
        return 0


if __name__ == '__main__':
    # login('18888888888', '888888')
    print("111")